# coding=utf-8
from __future__ import print_function, absolute_import, unicode_literals
from gm.api import *

import pandas as pd
import numpy as np
# ==============================================================
# 读取文本文件
file_path = 'E:\\自选股.EBK'  # 替换为你的文件路径
data = pd.read_csv(file_path, delimiter='\t', header=None, dtype=str)
# 将DataFrame转换为字符串列表
string_list = data.iloc[:, 0].tolist()

# 替换第一个字符
modified_string_list = [
    'SHSE.' + s[1:] if s.startswith(('1', '2')) else 'SZSE.' + s[1:] if s.startswith('0') else s
    for s in string_list
]
symbols_string = ','.join(modified_string_list)
# ==============================================================
def init(context):
    # 订阅600519和000001的分钟数据
    subscribe(symbols=symbols_string, frequency='60s', count=2)


def on_bar(context,bars):
    print('收到bars行情---', bars[0].symbol)

if __name__ == '__main__':
    run(strategy_id='afeb6601-3294-11ef-824f-0050b6c7fa6e',
        filename='main.py',
        mode=MODE_BACKTEST,
        token='ca9c4532786a122aa5ceb3fd726432862e046f91',
        backtest_start_time='2024-06-01 08:00:00',
        backtest_end_time='2024-06-10 16:00:00',
        backtest_adjust=ADJUST_PREV,
        backtest_initial_cash=10000000,
        backtest_commission_ratio=0.0001,
        backtest_slippage_ratio=0.0001,
        backtest_match_mode=1)